<?php
/**
 * 单例模式demo
 * Created by andyYu.
 * User: yuxianjun001@icloud.com
 * Date: 2018/3/8 0008
 * Time: 11:38
 */

namespace App\admin\controller;


class Single
{
    protected static $instance=null;
    private $name;

    /**
     * 声明私有构造方法为了防止外部代码使用new来创建对象。
     * Single constructor.
     */
    private function __construct()
    {

    }

    public static  function getInstance(){
        if(self::$instance===null){
            self::$instance=new self();
        }
        return self::$instance;
    }

    public function setName($name){
         $this->name=$name;
    }

    public function getName(){
        return $this->name;
    }
}
